package outputstream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {
    public static void main(String[] args) {
        //将D:/IO/demo01.txt  拷贝到D:/IO/demo02.txt
        String srcFilePath = "D:/IO/demo01.txt";
        String destFilePath = "D:/IO/demo02.txt";
        FileInputStream  fileInputStream = null;
        FileOutputStream fileOutputStream = null;

        try {
            fileInputStream = new FileInputStream(srcFilePath);
            fileOutputStream = new  FileOutputStream(destFilePath );

            byte[] buf = new byte[3];
            int readLen = 0;
            while ((readLen = fileInputStream.read(buf)) != -1){
                fileOutputStream.write(buf,0,readLen);
            }
            System.out.println("拷贝完成");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(fileInputStream !=null){
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if(fileOutputStream !=null){
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }


    }
}
